package org.spindle.dungeon.entities;

import org.newdawn.slick.Animation;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Input;
import org.spindle.dungeon.Constants;
import org.spindle.dungeon.EntityManager;
import org.spindle.dungeon.LevelProperties;

import java.util.List;


public class Sword extends GeneralEntity {

    public static final int DURATION = 20;
    public static final int LIFETIME = 5;
    int dx = 0;
    int dy = 0;

    @Override
    public void initialize() {
        //up
        animations[0] = new Animation(getAnimationArray(11, 0, 5),DURATION);

        //down
        animations[1] = new Animation(getAnimationArray(11, 1, 5), DURATION);

        //right
        animations[2] = new Animation(getAnimationArray(11, 2, 5), DURATION);

        //left
        animations[3] = new Animation(getAnimationArray(11, 3, 5), DURATION);

        hitBoxHeight = Constants.TILE_SIZE;
        lifeTime = LIFETIME;
        weapon = true;
    }

    @Override
    public void update(GameContainer gc, LevelProperties props) {

        lifeTime--;

        List<GeneralEntity> ent = EntityManager.getInstance().returnEntitiesAt(this, 0 ,0);
        if (ent != null) {
            for (GeneralEntity entity : ent) {
                if (Constants.debug)
                    System.out.println(entity);
                if (entity.lifeTime!=-1) {
                    entity.hurt = true;
                    entity.lifeTime--;
                    break;

                }
            }
        }
    }

    @Override
    public void reset() {
        lifeTime = LIFETIME;
    }
}
